//
//  PieChartView.m
//  iMoney
//
//  Created by Sean McGrail on 2/18/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "PieChartView.h"


#define PI 3.14159265358979323846
static inline float radians(double degrees) { return degrees * PI / 180; }

@implementation PieChartView


- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Initialization code
		self.backgroundColor = [UIColor clearColor];
    }
    return self;
}


- (void)drawRect:(CGRect)rect {
    
	CGRect parentViewBounds = self.bounds;
	CGFloat width = CGRectGetWidth(parentViewBounds);
	CGFloat height = CGRectGetHeight(parentViewBounds);
	
	
    // Get the graphics context and clear it
    CGContextRef ctx = UIGraphicsGetCurrentContext();
	// CGContextClearRect(ctx, rect);
	
	
	// define stroke color
	CGContextSetRGBStrokeColor(ctx, 1, 1, 1, 1.0);
	
	// define line width
	CGContextSetLineWidth(ctx, 4.0);
	

	int offset = 5;
	double a = 0;
	double b = 20; 
	double c = 200; 
	double d = 360; 
	
	//CGContextSetFillColor(ctx, CGColorGetComponents( [[UIColor greenColor] CGColor]));
	//	CGContextMoveToPoint(ctx, x+2*offset, y);
	//	CGContextAddArc(ctx, x+2*offset, y, 100, radians(0), radians(0), 0);
	//	CGContextClosePath(ctx);
	//	CGContextFillPath(ctx);
	
	CGFloat xhalf = width/2.0-40;
	CGFloat yhalf = height/2.0 +  60;
	
	
	CGContextSetFillColor(ctx, CGColorGetComponents( [[UIColor colorWithRed:15 green:165/255 blue:0 alpha:1 ] CGColor]));
	CGContextMoveToPoint(ctx, xhalf,yhalf);
	CGContextAddArc(ctx, xhalf, yhalf, 100, radians(a), radians(b), 0);
	CGContextClosePath(ctx);
	CGContextFillPath(ctx);
	
	CGPathRef title = makeRec(CGRectMake(xhalf+100,yhalf, 10,10), 3.0);
	CGContextAddPath(ctx, title);
	CGContextClosePath(ctx);
	CGContextFillPath(ctx);
	
	
	CGContextSetFillColor(ctx, CGColorGetComponents( [[UIColor colorWithRed:99/255 green:184/255 blue:255/255 alpha:1 ] CGColor]));
	CGContextMoveToPoint(ctx, xhalf, yhalf);
	CGContextAddArc(ctx, xhalf, yhalf, 100, radians(b), radians(c), 0);
	CGContextClosePath(ctx);
	CGContextFillPath(ctx); 
	
	CGContextSetFillColor(ctx, CGColorGetComponents( [[UIColor colorWithRed:99/255 green:184/255 blue:80/255 alpha:1 ] CGColor]));
	CGContextMoveToPoint(ctx, xhalf, yhalf);
	CGContextAddArc(ctx, xhalf, yhalf, 100, radians(c), radians(d), 0);
	CGContextClosePath(ctx);
	CGContextFillPath(ctx); 
	
	
}


- (void)dealloc {
    [super dealloc];
}


@end
